<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-recharge"></i> 提现审核
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-row>
                    <el-col :span="10" style="display:flex;justify-content: flex-start;">
                        <el-input
                            v-model="query.name"
                            placeholder="用户手机号"
                            class="handle-input mr10"
                            style="width:120px;"
                        ></el-input>
                        
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-download" @click="exportSource">导出数据</el-button>
                    </el-col>
                </el-row>
                <el-row style="margin-top: 10px">
                    <el-col :span="4" style="display:flex;justify-content: flex-start;">
                        总共积分:{{coin_total.total_coin}}
                    </el-col>
                    <el-col :span="4" style="display:flex;justify-content: flex-start;">
                        总共锁定积分：{{coin_total.total_lockcoin}}
                    </el-col>
                    <el-col :span="4" style="display:flex;justify-content: flex-start;">
                        总共佣金合计：{{coin_total.total_commission}}
                    </el-col>
                    <el-col :span="4" style="display:flex;justify-content: flex-start;">
                        总共佣金转积分：{{coin_total.total_commission_jf}}
                    </el-col>
                    <el-col :span="5" style="display:flex;justify-content: flex-start;">
                        总共转账积分：{{coin_total.total_zhuan_jf}}
                    </el-col>
                </el-row>
            </div>
            <el-table
                :data="tableData"
                border
                v-loading="loading"
                 id="buctable"
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" sortable width="55" align="center"></el-table-column>
                <el-table-column label="用户" prop="mobile" align="center"></el-table-column>
                <el-table-column prop="change" label="账户剩余">
                    <template slot-scope="scope">
                        {{scope.row.coin}}

                    </template>
                </el-table-column>
                <el-table-column prop="change" label="变动积分">
                   <template slot-scope="scope">
                       <span v-if="scope.row.type =='+'" style="color:#67C23A">{{scope.row.type}}</span> <span v-else style="color:red">{{scope.row.type}}</span>{{scope.row.change}}
                       
                    </template>
                </el-table-column>

                <el-table-column prop="remark" label="描述"></el-table-column>
                <el-table-column prop="created_at" label="创建时间"></el-table-column>
                
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                     layout="total, prev, pager, next,sizes"
                    :page-sizes="[0,10, 20, 50,100 ,500,1000]"
                    @size-change="handleSizeChange"
                    :current-page="query.page"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>

export default {
  name: 'deposit',
  data () {
    return {
      query: {
        page: 1,
        pageSize: 10,
        name:'',
      },
      loading: false,
      tableData: [],
      multipleSelection: [],
      pageTotal: 0,
      delList: [],
      idx: -1,
      id: -1,
       coin_total: {
          total_coin:'0.00',
          total_commission:'0.00',
          total_lockcoin:'0.00',
          total_commission_jf:'0.00',
          total_zhuan_jf:'0.00',
       },
      //获取列表请求
      getList: function () {
        let that = this;
        this.api.post('coinlist', this.query, res => {
          for (let i in res.data.list) {
            res.data.list[i].status = res.data.list[i].status + '';
          }
          that.tableData = res.data.list;
          that.query.page = res.data.page;
          that.query.pageSize = res.data.pageSize;
          that.pageTotal = res.data.pageTotal;
          that.coin_total.total_coin = res.data.total_coin
          that.coin_total.total_lockcoin = res.data.total_lockcoin
          that.coin_total.total_commission = res.data.total_commission
            that.coin_total.total_commission_jf = res.data.total_commission_jf
            that.coin_total.total_zhuan_jf = res.data.total_zhuan_jf
        }, undefined, undefined, this);
      },
      //删除请求
      delLists: function (ids, msg) {
        let that = this;
        if (ids.length < 1) {
          this.$message.error('请选择删除的数据');
          return false;
        }
        // 二次确认删除
        this.$confirm('确定要删除吗？', '提示', {
          type: 'warning'
        }).then(() => {
          that.api.delete('delGoodsUnitTime', { ids: ids }, res => {
            that.query.page = 1;
            that.getList();
            that.multipleSelection = [];
            that.$message.success(res.msg);
          }, undefined, undefined, this);
        }).catch(() => { });
      }
    };
  },
  created () {
    this.getList();

  },
  methods: {
    // 触发搜索按钮
    handleSearch () {
      this.$set(this.query, 'page', 1);
      this.getList();
    },
    exportSource(){
      this.api.exportExcel(document.querySelector('#buctable'),'用户积分记录数据表')
    },
    handleSizeChange(val){
      console.log(val)
      if(val == 0){
        this.query.pageSize = 100000000;
      }else{
        this.query.pageSize = val;
      }
      this.getList();
    },

    /**
     * 添加编辑
     */
    handleEdit (index, row, status) {
      this.$confirm('确定要' + (status == 1 ? '通过' : '拒绝') + '审核吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.api.put('statusDeposit', { id: row.id, status: status }, res => {
          this.tableData[index].status = status;
          this.$message.success(res.msg);
          this.getList();
        });
      }).catch(() => { });
    },


    // 多选操作
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },

    // 删除操作
    handleDelete (index, row) {
      this.delLists([row.id], '删除成功');
    },
    //批量删除
    delAllSelection () {
      const length = this.multipleSelection.length;
      let str = '';
      this.delList = this.delList.concat(this.multipleSelection);
      let ids = [];
      for (let i = 0; i < length; i++) {
        str += this.multipleSelection[i].name + ' ';
        ids.push(this.multipleSelection[i].id);
      }
      this.delLists(ids, `删除了${str}`);
    },

    // 分页导航
    handlePageChange (val) {
      this.$set(this.query, 'page', val);
      this.getList();
    }
  }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
